import { useState, useEffect } from 'react';
import { Redirect } from 'react-router-dom';
import { observer, MobXProviderContext } from 'mobx-react';

function Login(props) {
  const [count, setCount] = useState(0);

  const { appStore } = useContext(MobXProviderContext);

  const { location } = props;
  function show() {
    console.log(1111);
  }
  useEffect(() => {
    show();
  }, []);
  if (appStore.isLogin) {
    const { redirect = '/' } = location.state || {};

    return <Redirect to={redirect} />;
  }
  return (
    <div>
      <button onClick={() => { setCount(count + 1); }}>{count}</button>
      <button onClick={() => { appStore.setLoginState(); }}>登录</button>
    </div>
  );
}

export default observer(Login);
